import axios from "axios";

function request(config) {
  const instance = axios.create({
    baseURL: "",
    // timeout: 5000,
  });
  return instance(config);
}

export function login(username, password) {
  // console.log(username,password);
  return request({
    url: "/api/user/login",
    method: "post",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    params: {
      username,
      password,
    },
  });
}

export function logout(token) {
  return request({
    url: "/api/user/logout",
    method: "get",
    headers: {
      Authorization: "bearer " + token,
    },
  });
}

export function quest(token) {
  return request({
    url: "/api/quest",
    method: "get",
    headers: {
      Authorization: "bearer " + token,
    },
  });
}

export function questPost(token, data) {
  console.log(token);
  return request({
    url: "/api/quest",
    method: "post",
    headers: {
      Authorization: "bearer " + token,
      "Content-Type": "application/json;charset=utf-8",
    },
    data,
  });
}

export function getDgutToken(token) {
  return request({
    url: "/api/login/dgut",
    method: "get",
    params:{
      token
    }
  });
}

export function questPostInMq(token, data) {
  return request({
    url: "/api/quest/mq",
    method: "post",
    headers: {
      Authorization: "bearer " + token,
      "Content-Type": "application/json;charset=utf-8",
    },
    data,
  });
}

export function getPollingRes(token) {
  return request({
    url: "/api/quest/polling",
    method: "get",
    headers: {
      Authorization: "bearer " + token,
    }
  });
}
